package com.li.test.model7;


import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Model7Controller {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/dlq")
    public ResponseEntity dlq(String msg,String key) {
        rabbitTemplate.convertAndSend("normal.exchange", "city.gz", "8秒过期",setExpiration("8000"));
        rabbitTemplate.convertAndSend("normal.exchange", "city.gz", "5秒过期",setExpiration("5000"));
        rabbitTemplate.convertAndSend("normal.exchange", "city.gz", "3秒过期",setExpiration("3000"));
        return ResponseEntity.ok("消息发送成功！");
    }
    // 编写方法，用来设置过期时间
    private MessagePostProcessor setExpiration(String time) {
        MessagePostProcessor processor = message -> {
            //设置过期时间
            message.getMessageProperties().setExpiration(time);
            return message;
        };
        return processor;
    }
}
